<?php
/**
 * PhpStorm
 * User: zu
 * Date: 2019/2/25
 */

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class BaseLog extends Model
{
    protected $table = 'base_log';
    protected $fillable = ['route', 'user_name', 'request', 'create_time'];

    /**
     * 后台日志记录
     * @param $masterName 操作人
     * @param $route 路由信息
     * @param $request 请求参数
     * @return bool
     */
    public function addMasterLog($masterName, $route, $request)
    {
        try {
            $data = [
                'route'     => $route,
                'user_name' => $masterName,
            ];
            $data['request'] = is_array($request) ? json_encode($request) : $request;

            $this->insert($data);

            return true;
        } catch (\Exception $e) {
            dd($e->getMessage());
            return false;
        }
    }
}